package com.siwei.infoextract.rule;

import com.siwei.infoextract.wrapper.featureextract.AnnotationOutputter;
import com.siwei.infoextract.wrapper.featureextract.InnerTextFeatureExtractor;
import com.siwei.infoextract.wrapper.parser.DomNode;

public class IsOrganizationPatternCriteria extends Criteria {
	public IsOrganizationPatternCriteria(String criteriaName, String criteriaValue) {
		super(criteriaName, criteriaValue);
	}

	public boolean doAction(DomNode domNode) {
		// do nothing in the super class
		InnerTextFeatureExtractor innerTextExtractor = new InnerTextFeatureExtractor();
		String innerText =  (String)innerTextExtractor.extract(domNode);

		innerText = innerText.trim();

		boolean keyworkdMatched = false;

		for (int i = 0; i < AnnotationOutputter.KEYWORDS.length; i++) {
			if (innerText.endsWith(AnnotationOutputter.KEYWORDS[i])) {
				keyworkdMatched = true;
				break;
			}
		}

		boolean value = Boolean.parseBoolean(criteriaValue);
		return value == keyworkdMatched;
	}
}
